package sudroid.net2;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import sudroid.CleanUtils;
import sudroid.FileUtil;
import sudroid.LogUtils;
import sudroid.security.MD5;

public class CacheHttpClient extends HttpClient
{
  private static FilenameFilter filter = new CacheHttpClient.1();
  static final String prex = "UNCOMPLETE_";
  private static final long serialVersionUID = 1880450304602276087L;
  private File cacheDir;

  public CacheHttpClient(File paramFile)
  {
    this.cacheDir = paramFile;
  }

  public CacheHttpClient(String paramString)
  {
    File localFile = new File(paramString);
    this.cacheDir = localFile;
  }

  public static void clearCacheFiles(File paramFile)
  {
    FilenameFilter localFilenameFilter = filter;
    File[] arrayOfFile = paramFile.listFiles(localFilenameFilter);
    int i;
    int j;
    if ((arrayOfFile != null) && (arrayOfFile.length > 0))
    {
      i = arrayOfFile.length;
      j = 0;
    }
    while (true)
    {
      if (j >= i)
        return;
      boolean bool = arrayOfFile[j].delete();
      j += 1;
    }
  }

  public static void clearCacheFiles(String paramString)
  {
    clearCacheFiles(new File(paramString));
  }

  public void cleanCache(String paramString)
  {
    boolean bool = FileUtil.deleteDependon(getPreHexDigestPath(paramString));
  }

  public void clearCacheFiles()
  {
    clearCacheFiles(this.cacheDir);
  }

  public String getCache(String paramString)
    throws HttpException
  {
    String str1 = getHexDigestPath(paramString);
    String str2 = getPreHexDigestPath(paramString);
    String str3;
    if (!isCached(paramString))
      if (isCaching(paramString))
        str3 = null;
    while (true)
    {
      return str3;
      Response localResponse = get(paramString);
      try
      {
        InputStream localInputStream = localResponse.asStream();
        FileOutputStream localFileOutputStream = new FileOutputStream(str2);
        BufferedOutputStream localBufferedOutputStream = new BufferedOutputStream(localFileOutputStream);
        FileUtil.copy(localInputStream, localBufferedOutputStream);
        CleanUtils.disconnectResponse(localResponse);
        File localFile1 = new File(str2);
        File localFile2 = new File(str1);
        if (!localFile1.renameTo(localFile2))
          str1 = null;
        boolean bool = FileUtil.deleteDependon(str2);
        str3 = str1;
      }
      catch (IOException localIOException)
      {
        while (true)
        {
          LogUtils.d("创建缓存失败");
          LogUtils.e(localIOException);
        }
      }
    }
  }

  String getHexDigestPath(String paramString)
  {
    String str1 = String.valueOf(this.cacheDir.getAbsolutePath());
    StringBuilder localStringBuilder = new StringBuilder(str1).append("/");
    String str2 = MD5.hexdigest(paramString);
    return str2;
  }

  String getPreHexDigestPath(String paramString)
  {
    String str1 = String.valueOf(this.cacheDir.getAbsolutePath());
    StringBuilder localStringBuilder = new StringBuilder(str1).append("/").append("UNCOMPLETE_");
    String str2 = MD5.hexdigest(paramString);
    return str2;
  }

  public boolean isCached(String paramString)
  {
    return FileUtil.doesExisted(getHexDigestPath(paramString));
  }

  public boolean isCaching(String paramString)
  {
    return FileUtil.doesExisted(getPreHexDigestPath(paramString));
  }
}

/* Location:           D:\Program Files\eclipse\apktool-r01-3\新浪微博\classes.dex.dex2jar.jar
 * Qualified Name:     sudroid.net2.CacheHttpClient
 * JD-Core Version:    0.6.0
 */